#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

extern int create_process(char *program, char **arg_list);

int create_process(char *program, char **arg_list) {
    pid_t child_pid;
//    child_pid = fork();
    child_pid;
    if (child_pid != 0)
        return child_pid;
    else {
        execvp(program, arg_list);
        abort();
    }
}

#include <stdio.h>
#include <stdlib.h>

int mainfirst() {
    printf("Hello, World!\n");
    printf("a:");
    int a;
    scanf("%d", &a);
    printf("Hello, World! %d \n", a);
    system("pause");
    return 0;
}

/**
 * 进程
 * @return
 */
int main_main() {
    char *arg_list[] = {
            "ls",
            "-l",
            "/Users/ycy",
            NULL
    };
    printf("hello world");
    create_process("ls", arg_list);
    return 0;
}

void ex(int *a);

/*
 * 数组
 */
int mainArr() {
    int a[2] = {1, 2};
    for (int i = 0; i < 2; i++) {
        printf("%d-%d,", i, a[i]);
        ex(&a[i]);
    }
    printf("\n");
    for (int i = 0; i < 2; i++) {
        printf("%d-%d,", i, a[i]);
    }
}

void ex(int *a) {
    *a = 0;
}

#include "string.h"

/**
 * 字符串
 * @return
 */
int main02() {
    char name[] = "hello world";
    // name sizeof 12
    printf("name %s sizeof %d strlen %d \n", name, sizeof(name), strlen(name));

    char name2[] = "hello world"
                   "hahah";

    //1 strlen 字符串长度，sizeof 字节数 + 1
    printf("name2 %s sizeof %d strlen %d \n", name2, sizeof(name2), strlen(name2));

    //2 不能重新赋值
//    name[] = "like";

    //3 字符串拼接
    strcat(name, name2);

    //4 计算字符串长度
    printf("strcat %s sizeof %d, strlen %d \n", name, sizeof(name), strlen(name));

    //字符串数组必须以\0结尾
    char str[] = {'J', 'u', 's', 't', '\0'};
    printf("%s", str);

    return 0;
}

/**
 * 输入
 * @return
 */
int maininput() {
    int a, b;
    printf("input a b: \n");
    scanf("%d%d", &a, &b);
    printf("a=%d,b=%d", a, b);
    return 0;
}

int main03() {
    char *input = "hello world ha";
    int length = strlen(input);
    printf("%d %d \n", length, sizeof(input));


    int ff = 0;
    for (int i = 0; i < length; i++) {
        printf("%c \n", input[i]);
        if (input[i] == ' ') {
            ff++;
        }
    }

    char *output = malloc(sizeof(char) * (length + ff + 1));
    printf("%d\n", sizeof (output));

    int rr = 0;
    for (int i = 0; i < length; ++i, ++rr) {
        if (input[i] == ' ') {
            output[rr] = '%';
            output[++rr] = '2';
            output[++rr] = '0';
        } else {
            output[rr] = input[i];
        }
    }
    output[rr] = '\0';

    printf("%s %llu %llu \n", output, strlen(output), (sizeof(output) / sizeof(char)));
    printf("sizeof %d \n", sizeof(output));
    printf("sizeof %d ", sizeof(char ));


    for (int i = 0; i < strlen(output); ++i) {
    }

    return 0;
}